package com.asia.dao.ods;

import java.util.List;

import com.asia.domain.ods.AsiaUserTable;
import com.util.HibernateUtil;
import org.hibernate.Query;
import org.hibernate.Session;
 import org.hibernate.Transaction;


public class AsiaUserDao {

    Session session = null;
    public AsiaUserTable findUser(AsiaUserTable user){

        List<AsiaUserTable> list = null;
        AsiaUserTable userDetail = null;
        String hql = "from AsiaUserTable as user where user.userName=? and user.userPassword=?";

		/*ClassPathXmlApplicationContext tcx = new ClassPathXmlApplicationContext("applicationContext.xml");
		SessionFactory sessionFactory = (SessionFactory) tcx.getBean("sessionFactory");
		Session session = sessionFactory.openSession();*/
        session = (Session)HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction tx= session.beginTransaction();
        Query query=session.createQuery(hql);
        query.setString(0, user.getUserName());
        query.setString(1, user.getUserPassword());
        list = query.list();
        session.flush();
        session.clear();
        tx.commit();

        if (list != null && list.size() == 1)
        {
            userDetail = list.get(0);
        }
        return userDetail;
    }



}
